package com.team06.pojo;

import java.util.List;

public class PageResult<T> {
    private List<T> data;          // 数据列表
    private int currentPage;        // 当前页码
    private int pageSize;           // 每页条数
    private long totalRecords;      // 总记录数
    private int totalPages;         // 总页数

    // 构造方法
    public PageResult(List<T> data, int currentPage, int pageSize, long totalRecords) {
        this.data = data;
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalRecords = totalRecords;
        this.totalPages = (int) Math.ceil((double) totalRecords / pageSize);
    }

    // Getters
    public List<T> getData() {
        return data;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public int getPageSize() {
        return pageSize;
    }

    public long getTotalRecords() {
        return totalRecords;
    }

    public int getTotalPages() {
        if (pageSize == 0) return 0;
        return (int) Math.ceil((double) totalRecords / pageSize);
    }

    // 分页状态方法
    public boolean hasPrevious() {
        return currentPage > 1;
    }

    public boolean hasNext() {
        return currentPage < totalPages;
    }

    // 静态构造方法
    public static <T> PageResult<T> of(List<T> data, int page, int pageSize, long total) {
        return new PageResult<>(data, page, pageSize, total);
    }
}